﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.Data;
using System.IO;




namespace DAO
{
    public class SqlDataConnectHelper
    {
        #region ConnectionString
        protected static String connectionString;
        public static String ConnectionString
        {
            get
            {

                return @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ManagerAgency.mdf;Integrated Security=True;User Instance=True";
                //return ReadConnectionString("Web.config");
            }
        }
       

        #endregion
        #region ExecuteQuery
        public static DataTable ExecuteQuery(String spName, List<SqlParameter> sqlParams)
        {
            DataTable dt = new DataTable();

            SqlConnection connect = new SqlConnection(ConnectionString);
            connect.Open();

            SqlCommand command = connect.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = spName;
            if (sqlParams != null)
            {
                foreach (SqlParameter param in sqlParams)
                {
                    command.Parameters.Add(param);
                }
            }
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = command;
            adapter.Fill(dt);



            return dt;
        }
        public static DataTable ExecuteQuery(String spName)
        {
            return ExecuteQuery(spName, null);
        }
        #endregion
        #region ExecuteNoneQuery
        public static int ExecuteNoneQuery(String spName, List<SqlParameter> sqlParams)
        {
            int n;

            SqlConnection connect = new SqlConnection(ConnectionString);
            connect.Open();

            SqlCommand command = connect.CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = spName;
            if (sqlParams != null)
            {
                foreach (SqlParameter param in sqlParams)
                {
                    command.Parameters.Add(param);
                }
            }
            n = command.ExecuteNonQuery();


            return n;
        }
        public static int ExecuteNoneQuery(String spName)
        {
            return ExecuteNoneQuery(spName, null);
        }
        #endregion
    }
}
